package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.SmtpServer;
import service.POP3Server;
/**
 * Servlet implementation class ProtolControl
 */
@WebServlet("/ProtolControl")
public class ProtolControl extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ProtolControl() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		int type =Integer.parseInt(request.getParameter("type"));
		if(type==1) {
			new SmtpServer().start();
			System.out.println("start smtp");
		}
		else if(type==2) {
			SmtpServer.close();
			System.out.println("close smtp");
		}else if(type==3) {
			new POP3Server().start();
			System.out.println("start pop3");
		}else if(type==4){
			POP3Server.close();
			System.out.println("close pop3");
		}
}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
